#ifndef __IDE_H
#define __IDE_H

#include"global.h"
#include"sync.h"
#include"list.h"
#include"super_block.h"
#include"bitmap.h"

struct partition{
	char name[8];
	uint32_t start_lba;
	uint32_t sec_cnt;
	struct super_block* sb; 		
	bitmap block_bitmap;
	bitmap inode_bitmap;
	list open_inode_list;
	list_elem tag;
	struct disk* disk;
};

struct disk{
	char name[8];
	struct channel* ch;
	uint8_t dev_no;
	struct partition primary_part[4];
	struct partition logic_part[8];
};

struct channel{
	char name[8];
	uint16_t port_base;
	uint32_t irq;
	semphore disk_done;
	bool wait_intr;
	struct disk devices[2];
};

struct partition_entry{
	uint8_t boot_flag;
	uint8_t start_head;
	uint8_t start_sec;
	uint8_t start_cyl;
	uint8_t fs_type;
	uint8_t end_head;
	uint8_t end_sec;
	uint8_t end_cyl;
	uint32_t start_lba;
	uint32_t sec_cnt;
}__attribute__((packed));

//define boot sector
struct boot_sector{
	uint8_t code[446];
	//disk partition table
	struct partition_entry dpt[4];
	uint16_t magic;
}__attribute__((packed));

struct disk* nm2disk(uint8_t,uint8_t);

void ide_read(struct disk* d,char* buff,uint32_t lba,uint32_t s_cnt);

void ide_write(struct disk* d,char* buff,uint32_t lba,uint32_t s_cnt);

void init_ide(void);

#endif
